//
//  UIColor+WTExtend.m
//  WTLiveSDKDemo
//
//  Created by ben on 16/10/11.
//  Copyright © 2016年 ben. All rights reserved.
//

#import "UIColor+WTExtend.h"

@implementation UIColor (WTExtend)
+ (UIColor *)hexChangeFloat:(NSString *) hexColor
{
    return [self hexChangeFloat:hexColor AndAlpha:1.0];
}

+ (UIColor *)hexChangeFloat:(NSString *)hexColor AndAlpha:(float)alpha{
    if (hexColor && [hexColor isKindOfClass:[NSString class]] && hexColor.length>=4) {
        unsigned int redInt_, greenInt_, blueInt_;
        NSRange rangeNSRange_;
        rangeNSRange_.length = 2;  // 范围长度为2
        
        // 取红色的值
        rangeNSRange_.location = 0;
        [[NSScanner scannerWithString:[hexColor substringWithRange:rangeNSRange_]]
         scanHexInt:&redInt_];
        
        // 取绿色的值
        rangeNSRange_.location = 2;
        [[NSScanner scannerWithString:[hexColor substringWithRange:rangeNSRange_]]
         scanHexInt:&greenInt_];
        
        // 取蓝色的值
        rangeNSRange_.location = 4;
        [[NSScanner scannerWithString:[hexColor substringWithRange:rangeNSRange_]]
         scanHexInt:&blueInt_];
        if (alpha > 1.0f) {
            alpha = 1;
        }else if (alpha < 0.0f){
            alpha = 0;
        }
        return [UIColor colorWithRed:(float)(redInt_/255.0f)
                               green:(float)(greenInt_/255.0f)
                                blue:(float)(blueInt_/255.0f)
                               alpha:alpha];
    }else
    {
        return nil;
    }
}

+ (UIColor*)themeColor{
    return [UIColor hexChangeFloat:@"FF7864"];
}
@end
